package com.jims.master.modules.activemq.mq.consumer.topic;

import com.jims.master.common.config.Global;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.sys.service.OrgRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 *
 * @author liang
 * @description  Topic消息监听器
 * @component （把普通pojo实例化到spring容器中，相当于配置文件中的<bean id="" class=""/>）
 */
@Component("topicReceiverRole")
public class TopicReceiverRole implements MessageListener{

    @Autowired
    private OrgRoleService orgRoleService;

	@Override
	public void onMessage(Message message) {
		try {
			System.out.println("topicReceiverRole接收到消息:"+((TextMessage)message).getText());
			String clientId = Global.getConfig("client_id");//获取某一个key的value: clientId=jims_htca
			if(StringUtils.isNotBlank(message.getStringProperty("client_id"))&&message.getStringProperty("client_id").equals(clientId)){
			}else{
				String type = message.getStringProperty("type");//update,add,delete
//                orgRoleService.synchroOrgRole(type,"",((TextMessage)message).getText());
			}
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
